local opt = vim.opt
local bo = vim.bo
local g = vim.g
local o = vim.o
local b = vim.b

-- pacman -S neovide
if g.neovide then
  -- o.guifont = "Fira Code JetBrains Mono Nerd Font:h14"
  o.guifont = "Source Code Pro:h14"
  -- Helper function for transparency formatting
  local alpha = function()
    return string.format("%x", math.floor(255 * (vim.g.transparency or 0.8)))
  end
  -- g:neovide_transparency should be 0 if you want to unify transparency of content and title bar.
  g.neovide_transparency = 0.0
  g.transparency = 0.8
  g.neovide_background_color = "#0f1117" .. alpha()

  g.neovide_cursor_animation_length = 0.13
  g.neovide_cursor_trail_size = 0.8
  g.neovide_cursor_vfx_mode = "pixiedust"
end

-- 全局引导键
g.mapleader = ","
g.maplocalleader = ","
vim.api.nvim_set_keymap("n", ",", "", { noremap = true })

-- 命令行历史留存记录数量
opt.history = 10

-- utf8
g.encoding = "utf-8"
o.termencoding = "utf-8"
opt.fileencoding = "utf-8"
b.fileencoding = "utf-8"
vim.scriptecoding = "utf-8"

-- update interval for gitsigns
o.updatetime = 100
-- keymap timeout
o.timeoutlen = 500

-- 1 不显示 2 显示  会影响 bufferline 的是否显示
-- vim.o.showtabline = 2
-- 命令行高，提供足够的显示空间
o.cmdheight = 1
-- 末行模式命令补全增强
o.wildmenu = true
opt.completeopt = { "menuone", "noselect" } -- must just for cmp
-- 显示行号
opt.number = true
-- 使用相对行号
opt.relativenumber = true

-- 当文件被外部程序修改时，自动加载
opt.autoread = true
bo.autoread = true
opt.autowrite = true

-- 禁止创建备份文件
opt.backup = false
opt.writebackup = false
opt.swapfile = false

-- 显示一些可见字符
o.list = true
-- o.listchars        = "tab:> ,trail:·,space:·,eol:↴"
-- o.listchars = "tab:> ,trail:·,space:·"
o.listchars = "tab:>~,trail:·,space:·"
opt.backspace = "start,eol,indent"

-- 搜索
opt.ignorecase = true
opt.smartcase = true
-- 搜索高亮
opt.hlsearch = true
-- 边输入边搜索
opt.incsearch = true

-- 新的分割窗口在右边和下边出现
opt.splitright = true
opt.splitbelow = true

-- 当前行下划线标识
opt.cursorline = true
-- 当前行背景标识
opt.termguicolors = true
opt.winblend = 0

-- 编辑器左侧会多一列, 显示一些图标指示
opt.signcolumn = "yes"
-- 右侧参考线，超过表示代码太长了，考虑换行
-- opt.colorcolumn = "80"
opt.colorcolumn:append("80")
opt.colorcolumn:append("100")
opt.colorcolumn:append("120")

-- 缩进
opt.autoindent = true
opt.tabstop = 2
opt.shiftwidth = 2
opt.softtabstop = -1 -- ofttabstop的值为负数,会使用shiftwidth的值,两者保持一致,方便统一缩进.
opt.expandtab = true -- 输入Tab字符时,自动替换成空

-- opt.scrolloff = 10   -- 预留屏幕上下的10行可见
opt.ai = true   -- Auto indent
opt.si = true   -- Smart indent
opt.wrap = true -- No wrap lines

-- 不显示显示当前的模式，交给插件 lualine.nvim 了
opt.showmode = false

-- 光标快速一定能够
opt.whichwrap = "b,s,<,>,[,],h,l"

-- 启用鼠标
opt.mouse:append("a")
opt.clipboard:append({ "unnamedplus" })
opt.clipboard:prepend({ "unnamed", "unnamedplus" })

-- 撤销数据文件存储
opt.undofile = true
opt.undodir = vim.fn.expand("$HOME/.local/share/nvim/undo")

-- 词 - _ 连接 作为一个词
-- opt.iskeyword = "-,_"

-- opt.spell = true
-- opt.spelllang = { "en_us" }

-- 表示每个项目目录下都可以存在 .nvim.lua 文件的配置信息
opt.exrc = true

-- Finding files - Search down into subfolders
opt.path:append("**")
opt.wildignore:append({
  "*/node_modules/*",
  "*/target/*",
})

-- -- 相关提示信息在左侧预留列显示图标
-- vim.fn.sign_define({
--   {
--     name = 'DiagnosticSignError',
--     text = ' ',
--     texthl = 'DiagnosticSignError',
--     linehl = 'ErrorLine',
--   },
--   {
--     name = 'DiagnosticSignWarn',
--     text = ' ', -- ''
--     texthl = 'DiagnosticSignWarn',
--     linehl = 'WarningLine',
--   },
--   {
--     name = 'DiagnosticSignInfo',
--     text = ' ', -- '',
--     texthl = 'DiagnosticSignInfo',
--     linehl = 'InfoLine',
--   },
--   {
--     name = 'DiagnosticSignHint',
--     text = '󰌵 ',
--     texthl = 'DiagnosticSignHint',
--     linehl = 'HintLine',
--   },
-- })


-- replace default diagnostic signs
-- more:https://neovim.io/doc/user/diagnostic.html#diagnostic-signs
-- local signs = { Error = "󰅚", Warn = "", Hint = "", Info = "" }
local signs = { Error = "", Warn = "", Hint = "󰌵", Info = "" }
for type, icon in pairs(signs) do
  local hl = "DiagnosticSign" .. type
  vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
